package com.xzgj.fmmall.service.impl;

import com.xzgj.fmmall.dao.InterestsMapper;
import com.xzgj.fmmall.entity.Interests;
import com.xzgj.fmmall.service.InterestsService;
import com.xzgj.fmmall.vo.ResStatus;
import com.xzgj.fmmall.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

@Service
public class InterestsServiceImpl implements InterestsService {

    @Resource
    private InterestsMapper interestsMapper;

    @Override
    public ResultVO insertInterests(Interests interests) {
        if (interests == null || interests.getInterest_id().length() == 0 || interests.getInterest_name().length() == 0){
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);
        }
        String interestId = new Random().nextInt(899) + 100 + "";

        interests.setInterest_id(interestId);
        interests.setInterest_name(interests.getInterest_name());
        int result = interestsMapper.insert(interests);
        if (result > 0){
            return new ResultVO(ResStatus.OK,ResStatus.SUCCESS,null);
        }else {
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);

        }
    }

    @Override
    public ResultVO queryInterestsByInterestsId(int interestsId) {
        Interests interests = interestsMapper.queryInterestsByInterestsId(interestsId);
        if (interests != null) {
            return new ResultVO(ResStatus.OK, ResStatus.SUCCESS,interests);
        }else {
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);
        }
    }

    @Override
    public ResultVO updateInterestsInfoByInterestsId(Interests interests) {
        if (interests == null || interests.getInterest_id().length() == 0 || interests.getInterest_name().length() == 0){
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);
        }
        int result = interestsMapper.updateInterestsInfoByInterestsId(interests, Integer.parseInt(interests.getInterest_id()));
        if (interests != null) {
            return new ResultVO(ResStatus.OK, ResStatus.SUCCESS,interests);
        }else {
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);
        }
    }


    @Override
    public ResultVO deleteInterestsInfoByInterestsId(int interestsId) {
        int result = interestsMapper.deleteInterestsInfoByInterestsId(interestsId);
        if (result > 0) {
            return new ResultVO(ResStatus.OK, ResStatus.SUCCESS,null);
        }else {
            return new ResultVO(ResStatus.NO,ResStatus.FAILURE,null);
        }
    }

    @Override
    public ResultVO queryInterests() {
        return new ResultVO(ResStatus.OK,ResStatus.SUCCESS,interestsMapper.queryInterests());
    }
}
